<!doctype html>
<html>
<head>
<meta charset="utf-8">
    <title>设置及修改密码</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">     
    <meta content="yes" name="apple-mobile-web-app-capable">     
    <meta content="black" name="apple-mobile-web-app-status-bar-style">     
    <meta content="telephone=no" name="format-detection">
    <link rel="shortcut icon" href="/favicon.ico">
    <link rel="stylesheet" type="text/css" href="/H5/css/sm.min.css" />
    <link rel="stylesheet" type="text/css" href="/H5/css/reset.css?v=1" />
</head>               
<body>
	<div class="page-group ms-controller" :controller="password">
        <div class="page page-current">
            <header class="bar bar-nav">
              	<a class="icon icon-left pull-left" href="javascript:window.history.go(-1);"></a>
              	<a class="icon icon-home pull-right" href="/H5"></a>
              	<h1 class="title">设置及修改密码</h1>
            </header>
            <div class="content">
            	<div class="buttons-tab">
            	    <a :on-click="@jump(1,true)" class="tab-link button type1">修改登录密码</a>
            	    <a :on-click="@jump(2,true)" class="tab-link button type2">设置支付密码</a>
            	</div>
                <div :if="@type==1" class="list-block">
                    <ul class="block-ul">
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title label">新密码</div>
                                    <div class="item-input">
                                        <input type="password" :duplex="newPassword" placeholder="请输新密码">
                                    </div>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title label">确认新密码</div>
                                    <div class="item-input">
                                        <input type="password" :duplex="confirmPassword" placeholder="请再次输入新密码">
                                    </div>
                                </div>
                            </div>
                        </li>
                    </ul>    
                    <div class="content-block">
                        <div class="row">
                                <div class="col-50" style="width:48%;"><a href="javascript:;" :on-click="@submit" class="button button-big button-fill button-danger">确认并提交</a></div>
                        </div>
                    </div>
                </div>
                <div :if="@type==2"class="list-block">
                    <ul class="block-ul">
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title label">支付密码</div>
                                    <div class="item-input">
                                        <input type="password" :duplex="payPassword" placeholder="请输入支付密码">
                                    </div>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title label">确认支付密码</div>
                                    <div class="item-input">
                                        <input type="password" :duplex="confirmPayPassword" placeholder="请再次输入支付密码">
                                    </div>
                                </div>
                            </div>
                        </li>
                    </ul>    
                    <div class="content-block">
                        <div class="row">
                                <div class="col-50" style="width:48%;"><a href="javascript:;" :on-click="@submit" class="button button-big button-fill button-danger">确认并提交</a></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
<script type='text/javascript' src='/H5/js/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript' src='/H5/js/sm.min.js' charset='utf-8'></script>
<script type='text/javascript' src='/H5/js/avalon.js' charset='utf-8'></script>
<script type='text/javascript' src='/H5/js/simpleStorage.js' charset='utf-8'></script>
<script type='text/javascript' src='/H5/js/mall.js?v=10' charset='utf-8'></script>
<script>
    var password = avalon.define({
        $id: "password",
        type: Mall.parseUrl( window.location.href ).type,
        payPassword: "",
        newPassword: "",
        confirmPassword: "",
        confirmPayPassword: "",
        submit: function(){
        	if( password.type == 2 ){
	            if( !password.payPassword ){
	                $.toast( "请输入支付密码", 2000, "warning" )
	                return
	            }
	            if( !password.confirmPayPassword ){
	                $.toast( "请再次输入支付密码", 2000, "warning" )
	                return
	            }
	            if( password.payPassword != password.confirmPayPassword ){
	                $.toast( "两次输入不一致", 2000, "warning" )
	                return
	            }
	            $.prompt("请输入原支付密码", function( value ){
	                var postData = {
	                    old_password: value,
	                    pay_password: password.payPassword
	                }
	                Mall.request( "/api/ChangePayPassword", postData )
	                    .always( function( data ){
	                        if( data.error_code == 0 ){
	                            $.toast( "支付密码修改成功", 1000, "success", function(){
	                                if( window.location.href.indexOf( "&jumpurl=" ) > -1 ){
	                                    window.location.href = window.location.href.split( "&jumpurl=" )[1];
	                                }
	                                else{
	                                    window.location.href="/H5/member";
	                                }
	                            } )
	                        }
	                    } )
	            })
	            $( "input.modal-text-input" ).attr( "type", "password" );
        	}
        	else{
        		if( !password.newPassword ){
        		    $.toast( "请输入新密码", 2000, "warning" )
        		    return
        		}
        		if( !password.confirmPassword ){
        		    $.toast( "请输入新密码", 2000, "warning" )
        		    return
        		}
        		if( password.newPassword != password.confirmPassword ){
        		    $.toast( "两次输入不一致", 2000, "warning" )
        		    return
        		}
        		$.prompt("请输入原登录密码", function( value ){
        		    var postData = {
        		        old_password: value,
        		        new_password: password.newPassword,
        		        confirm_password: password.confirmPassword
        		    }
        		    Mall.request( "/api/ChangePassword", postData )
        		        .always( function( data ){
        		            if( data.error_code == 0 ){
        		                $.toast( "登陆密码修改成功", 1000, "success", function(){
        		                    window.location.href="/H5/member";
        		                } )
        		            }
        		            else{
        		                $.alert(data.error_msg);
        		            }
        		        } )
        		})
        		$( "input.modal-text-input" ).attr( "type", "password" );
        	}
        },
        jump: function( e, o ){
        	if( e ){
        		if( !$( "a.type"+e ).hasClass( "active" ) ){
	        		$( ".tab-link" ).removeClass( "active" );
	        		$( "a.type"+e ).addClass( "active" );
	        		if( o ){
	        			window.history.replaceState(null, null, window.location.href.split("=")[0]+"="+e); 
	        		}
        		}
        		password.type = e
        	}
        }
    })
    password.jump( password.type );
    avalon.scan( document.body );
</script>
</body>
</html>
